/*
 * @lc app=leetcode.cn id=128 lang=golang
 *
 * [128] 最长连续序列
 */

// @lc code=start

func longestConsecutive(nums []int) int {
	res := make(map[int]struct{})
	for _, v := range nums {
		res[v] = struct{}{}
	}
	longest := 0

	for k, _ := range res {
		if _, ok := res[k-1]; !ok {
			curlong := 1
			for i := k + 1; ; i++ {
				if _, o := res[i]; o {
					curlong++
				} else {
					break
				}
			}
			if curlong > longest {
				longest = curlong
			}
		}
	}
	return longest

}

// @lc code=end
